package com.ruoyi.service.jpjs.concrete.impl;

import com.ruoyi.common.core.domain.Ztree;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.domain.jpjs.common.concrete.Concrete;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.mapper.jpjs.concrete.ConcreteMapper;
import com.ruoyi.service.jpjs.concrete.ConcreteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author C.fw
 * @explain 混凝土报表业务层处理
 * @since 2020/8/15 15:43
 */
@Service
public class ConcreteServiceImpl implements ConcreteService {

    @Autowired
    private ConcreteMapper concreteMapper;

    @Override
    public int updateConcreteById(Concrete concrete) {
        return concreteMapper.updateConcreteById(concrete);
    }

    @Override
    public List<Map<String, Object>> selectBuildingNumberList(Map<String, Object> map) {
        return concreteMapper.selectBuildingNumberList(map);
    }

    @Override
    public int deleteUserBycheckId(String checkIdArr) {
        String[] checkId = Convert.toStrArray(checkIdArr);
        return concreteMapper.deleteUserBycheckId(checkId);
    }

    @Override
    public List<Concrete> checkConcreteUnique(Concrete concrete) {
        return concreteMapper.checkConcreteUnique(concrete);
    }

    @Override
    public List<String> selectProIdListByUserId(Long userId) {
        return concreteMapper.selectProIdListByUserId(userId);
    }

    @Override
    public List<Ztree> getProgramTree() {
        return initZtree(concreteMapper.getProgramTree(ShiroUtils.getSysUser().getUserId()));
    }

    @Override
    public List<Map<String, Object>> getProgramNameList() {
        return concreteMapper.getProgramNameList(ShiroUtils.getSysUser().getUserId());
    }

    @Override
    public int insertConcreteBatches(List<Concrete> concreteList) {
        return concreteMapper.insertConcreteBatches(concreteList);
    }

    public List<Ztree> initZtree(List<Map<String, Object>> projectList) {
        List<Ztree> ztrees = new ArrayList();
        for (Map<String, Object> map : projectList) {
            Ztree ztree = new Ztree();
            ztree.setId((String) map.get("id"));
            ztree.setpId((String) map.get("parentId"));
            ztree.setName((String) map.get("name"));
            ztree.setTitle((String) map.get("name"));
            ztree.setGrade((String) map.get("grade"));
            ztrees.add(ztree);
        }
        return ztrees;
    }

    @Override
    public List<Concrete> selectConcreteList(Map<String, Object> map) {
        return concreteMapper.selectConcreteList(map);
    }


    @Override
    public List<Map<String, Object>> selectConcreteDetailList(Map<String, Object> map) {
        return concreteMapper.selectConcreteDetailList(map);
    }

}
